package com.mysoft.main.main.controller;

import com.mysoft.common.enmus.DataSourceType;
import com.mysoft.common.entity.User;
import com.mysoft.service.service.HelloService;
import com.mysoftbase.base.holder.DataSourceContextHolder;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.sql.DataSource;
import java.util.List;

/**
 * @Author: John
 * @Date 2019-12-16 19:53
 */
@RestController
@RequestMapping("/hello")
public class HelloController {

    @Autowired
    private HelloService helloService;

    @Resource(name = "masterDataSource")
    private DataSource masterDataSource;

    @Resource(name = "antherDataSource")
    private DataSource antherDataSource;

    @GetMapping
    public String hello() {
        System.out.println("tetsetestsetestsets");
        System.out.println(antherDataSource);
        System.out.println(masterDataSource);
        System.out.println("测试dev分支");
        return "Hello World !";
    }

    @GetMapping("all")
    public List<User> getAll() {
        return helloService.getAll();
    }

    @GetMapping("get")
    @RequiresPermissions("sysyas:tyst")
    public List<User> get() {
        return helloService.getAnther();
    }

    @GetMapping("getlist")
    public List<User> getList() {
        DataSourceContextHolder.setDataSource(DataSourceType.MASTER.value);
        return helloService.list();
    }

    @GetMapping("getAllList")
    public List<User> getAllList() {
        DataSourceContextHolder.setDataSource(DataSourceType.ANTHER.value);
        return helloService.list();
    }


}
